<?php
include('../../inc/global.inc');
$url=$_SERVER['HTTP_REFERER'];
?>
<?php
if($_POST[tj_act]){
   $z_rs=@mysql_query("select * from zd_class where id='$_POST[big_id]'");
   $z_row=@mysql_fetch_array($z_rs);
   $z_rs2=@mysql_query("select * from zd_class where id='$_POST[smid_id]'");
   $z_row2=@mysql_fetch_array($z_rs2);
   $z_sh=$_POST[z_sh]?$_POST[z_sh]:0;
   $z_tj=$_POST[z_tj]?$_POST[z_tj]:0;
   mysql_query("insert into ziliao  (z_title,z_bigid,z_bigname,z_smid,z_smname,z_content,z_dizhi,z_sh,z_tj) values ('$_POST[z_title]','$_POST[big_id]','$z_row[z_name]','$_POST[smid_id]','$z_row2[z_name]','$_POST[z_content]','$_POST[picture]','$z_sh','$z_tj')");
   echo "<script>alert('发布成功');location='index.php';</script>";
}
?>
<?php
if($_POST['xg_act']){
   $z_rs=@mysql_query("select * from zd_class where id='$_POST[big_id]'");
   $z_row=@mysql_fetch_array($z_rs);
   $z_rs2=@mysql_query("select * from zd_class where id='$_POST[smid_id]'");
   $z_row2=@mysql_fetch_array($z_rs2);
   $z_sh=$_POST[z_sh]?$_POST[z_sh]:0;
   $z_tj=$_POST[z_tj]?$_POST[z_tj]:0;


mysql_query("update ziliao set z_title='$_POST[z_title]',z_bigid='$_POST[big_id]',z_bigname='$z_row[z_name]',z_smid='$_POST[smid_id]',z_smname='$z_row2[z_name]',z_content='$_POST[z_content]',z_dizhi='$_POST[picture]',z_sh='$z_sh',z_tj='$z_tj' where id='".$_POST['iid']."'");

echo "<script>alert('修改成功');location='".$_POST['urls']."';</script>";

}
?>
<HTML>
<HEAD>
<TITLE>Admin</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<LINK href="../css/css.css" rel=stylesheet>
<script type='text/javascript' src="../js/islogin.js" charset="gb2312"></script>
<BODY>
<center>
<script language = "JavaScript">    
var onecount;    
onecount=0;    
subcat = new Array();
<?
$sql = "select * from zd_class order by id asc";
$result = mysql_query($sql);
$count = 0;    
while($res = mysql_fetch_array($result)){    
?>    
subcat[<?=$count?>] = new Array("<?=$res[z_name]?>","<?=$res[z_id]?>","<?=$res['id']?>");    
<?    
$count++;    
}    
echo "onecount=$count;";    
?>    
//联动函数    
function changelocation(locationid)    
{    
document.form1.smid_id.length = 0;     
var locationid=locationid;    
var i;    
for (i=0;i<onecount;i++)    
       { if(i==0){     
          document.form1.smid_id.options[document.form1.smid_id.length]=new Option("--二级分类--","");
		  }
         if(subcat[i][1]==locationid)    
         {     
          document.form1.smid_id.options[document.form1.smid_id.length] = new Option(subcat[i][0], subcat[i][2]);    
         }           
       }    
}   
</script>
<table width="90%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
  <tr>
    <td height="25" bgcolor="#EEEEF9" style="padding-left:5px;">三帝资料&nbsp;&nbsp;<a href="javascript:history.go(-1)">返回</a></td>
  </tr>
</table>
<?php
if($_GET[tj]){
?>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
<form method="post" action="" onSubmit="return check_ziliao()" name="form1">
    <tr>
      <td height="30" colspan="3" align="center" bgcolor="#8DA8CF"><strong>发布新资料</strong></td>
    </tr>
  <tr>
    <td width="142" height="25" align="center" bgcolor="#8DA8CF">资料主题</td>
    <td width="718" bgcolor="#FFFFFF" style="padding-left:4px;"><input name="z_title" type="text" size="50" maxlength="100"></td>
  </tr>
  <tr>
    <td height="25" align="center" bgcolor="#8DA8CF">资料分类</td>
	<td bgcolor="#FFFFFF" style="padding-left:4px;"><select name="big_id" onChange="changelocation(document.form1.big_id.options[document.form1.big_id.selectedIndex].value)">
<option value="">--选择一级分类--</option>    
<?    
$sql = "select * from zd_class where z_id=0";    
$result = mysql_query( $sql );    
while($res = mysql_fetch_array($result)){    
?>    
<option value="<?=$res['id']?>"><?=$res[z_name]?></option> 
<? } ?>    
</select>     
<select name="smid_id">                    
  <option value="">--选择二级分类--</option>
</select></td>
  </tr>
  <tr>
    <td height="25" align="center" bgcolor="#8DA8CF">详细内容</td>
    <td bgcolor="#FFFFFF" style="padding-left:4px;"><textarea name="z_content" cols="60" rows="12"></textarea></td>
  </tr>
 <tr>
	<td height="25" align="center" bgcolor="#8DA8CF">上传资料</td>
	<td bgcolor="#ffffff" style="padding-left:3px;"><input name="picture" type="text" id="picture" size="40">&nbsp;&nbsp;<input name="button" type="button" onClick="window.open ('zl_upfile.php', 'newwindow', 'height=50, width=400, top=250, left=250, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')" value="上传资料"></td>
	</tr>
  <tr>
    <td height="25" align="center" bgcolor="#8DA8CF">信息设置</td>
    <td bgcolor="#FFFFFF" style="padding-left:4px;">是否显示 <input name="z_sh" type="checkbox" value="1" checked>&nbsp;&nbsp;是否推荐 <input name="z_tj" type="checkbox" value="1"></td>
  </tr>
  <tr><input type="hidden" name="tj_act" value="ok">
    <td height="25" colspan="2" align="center" bgcolor="#FFFFFF"><input type="submit" value="提交"></td>
    </tr>
  </form>
</table>
<?php }?>
<?php
if($_GET['xg']){
$rs=mysql_query("select * from ziliao where id='".$_GET['xg_id']."'");
$row=mysql_fetch_array($rs);
?>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
<form method="post" action="" name="form1" onSubmit="return check_ziliao()">
    <tr>
      <td height="30" colspan="3" align="center" bgcolor="#8DA8CF"><strong>修改资料内容</strong></td>
    </tr>
  <tr>
    <td width="139" height="25" align="center" bgcolor="#8DA8CF">资料主题</td>
    <td width="721" bgcolor="#FFFFFF" style="padding-left:4px;"><input name="z_title" type="text" value="<?=$row[z_title]?>" size="50" maxlength="100"></td>
  </tr>
  <tr>
    <td height="25" align="center" bgcolor="#8DA8CF">资料分类</td>
    <td bgcolor="#FFFFFF" style="padding-left:4px;"><select name="big_id" onChange="changelocation(document.form1.big_id.options[document.form1.big_id.selectedIndex].value)">
<option value="">--选择大类--</option>    
<?    
$sql = "select * from zd_class where z_id=0";    
$result = mysql_query( $sql );    
while($res = mysql_fetch_array($result)){    
?>    
<option value="<?=$res['id']?>" <?php if($row[z_bigid]==$res[id]){echo "selected";}?>><?=$res[z_name]?></option> 
<? } ?>    
</select>     
<select name="smid_id">                    
  <option value="">--选择小类--</option>
  <?php $rs2=mysql_query("select * from zd_class where z_id='$row[z_bigid]'");
		while($row2=mysql_fetch_array($rs2)){
  ?>
    <option value="<?=$row2['id']?>" <?php if($row[z_smid]==$row2[id]){echo "selected";}?>><?=$row2[z_name]?></option>
    <?php }?>
</select></td>
  </tr>
  <tr>
    <td align="center" bgcolor="#8DA8CF">详细内容</td>
    <td bgcolor="#FFFFFF" style="padding-left:4px;"><textarea name="z_content" cols="60" rows="12"><?=$row[z_content]?></textarea></td>
  </tr>
   <tr>
	<td height="25" align="center" bgcolor="#8DA8CF">上传资料</td>
	<td bgcolor="#ffffff" style="padding-left:3px;"><input name="picture" type="text" id="picture" size="40" value="<?=$row[z_dizhi]?>">&nbsp;&nbsp;<input name="button" type="button" onClick="window.open ('zl_upfile.php', 'newwindow', 'height=50, width=400, top=250, left=250, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')" value="上传资料"></td>
	</tr>
  <tr>
    <td height="25" align="center" bgcolor="#8DA8CF">信息设置</td>
    <td bgcolor="#FFFFFF" style="padding-left:4px;">是否显示 <input name="z_sh" type="checkbox" value="1" <?php if($row[z_sh]==1){echo "checked";}?>>&nbsp;&nbsp;是否推荐 <input name="z_tj" type="checkbox" value="1" <?php if($row[z_tj]==1){echo "checked";}?>></td>
  </tr>
  <tr><input type="hidden" name="xg_act" value="ok"><input type="hidden" name="urls" value="<?=$url?>">
  <input type="hidden" name="iid" value="<?=$row['id']?>">
    <td height="25" colspan="2" align="center" bgcolor="#FFFFFF"><input type="submit" value="提交"></td>
    </tr>
  </form>
</table>
<?php }?>
</center>
</BODY>
</HTML>

<script language="javascript">
function $(id){
return document.getElementById(id);
}
function check_ziliao(){
if($("z_title").value==""){
alert("资料主题不能为空");
$("z_title").focus();
return false;
}
if($("big_id").value==""){
alert("资料分类不能为空");
$("big_id").focus();
return false;
}
if($("z_content").value==""){
alert("内容介绍不能为空");
$("z_content").focus();
return false;
}

if($("picture").value==""){
alert("请上传资料");
$("picture").focus();
return false;
}
}
</script>